  # -*- coding: utf-8 -*-

import db
reload( db)
from db import McfConnector


class Attribute_type():
	"""Description of an attribute type"""
	def __init__(self, libmyCF, attribute_type_id, name, type, definition, example):
		self.libmyCF = libmyCF
		self.attribute_type_id=attribute_type_id
		self.name=name
		self.type=type
		self.definition=definition   
		self.example=example

	def getCorrespondingAttributes( self):
		#should not use a sql request
		"""Returns the list of attributes corresponding to this attribute type"""
		result = []
		query="SELECT * FROM Attributes WHERE attribute_type_id = \"%d\""%( self. attribute_type_id)
		for data in self.libmyCF.connector.mcfQuery(query):
			result.append( Attribute( libmyCF = self.libmyCF, attribute_id = int(data[0]), attribute_type_id = int(data[1]), AE_id = int(data[2]), value = data[3]))
		return result[0] # There is just one attribute type of this name...

	def getId( self):
		return self.attribute_type_id

	def getType( self):
		return self.type
